import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controller.dart';

/// 倒计时圆圈组件
/// 
/// 特性：
/// - 数字切换动画
/// - 自定义样式
/// - 响应式更新
class CountdownCircle extends GetView<SplashController> {
  /// 圆圈大小
  final double size;
  
  /// 边框宽度
  final double borderWidth;
  
  /// 背景色
  final Color? backgroundColor;
  
  /// 边框颜色
  final Color? borderColor;
  
  /// 文字颜色
  final Color? textColor;
  
  /// 文字大小
  final double? fontSize;

  const CountdownCircle({
    super.key,
    this.size = 80,
    this.borderWidth = 2,
    this.backgroundColor,
    this.borderColor,
    this.textColor,
    this.fontSize,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: size,
      height: size,
      decoration: BoxDecoration(
        shape: BoxShape.circle,
        color: backgroundColor ?? Colors.white.withValues(alpha: 0.2),
        border: Border.all(
          color: borderColor ?? Colors.white.withValues(alpha: 0.4),
          width: borderWidth,
        ),
      ),
      child: Center(
        child: Obx(() => AnimatedSwitcher(
          duration: const Duration(milliseconds: 500),
          transitionBuilder: (child, animation) {
            return ScaleTransition(
              scale: animation,
              child: child,
            );
          },
          child: Text(
            '${controller.countdown.value}',
            key: ValueKey(controller.countdown.value),
            style: TextStyle(
              fontSize: fontSize ?? size * 0.45,
              fontWeight: FontWeight.bold,
              color: textColor ?? Colors.white,
            ),
          ),
        )),
      ),
    );
  }
}
